package com.link.wseller.mapper;

import com.link.wseller.domain.OrderDetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderDetailMapper {
    @Delete({
        "delete from order_detail",
        "where detail_id = #{detailId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String detailId);

    @Insert({
        "insert into order_detail (detail_id, order_id, ",
        "product_id, product_name, ",
        "product_price, product_quantity, ",
        "product_icon, create_time, ",
        "update_time)",
        "values (#{detailId,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR}, ",
        "#{productId,jdbcType=VARCHAR}, #{productName,jdbcType=VARCHAR}, ",
        "#{productPrice,jdbcType=DECIMAL}, #{productQuantity,jdbcType=INTEGER}, ",
        "#{productIcon,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(OrderDetail record);

    @InsertProvider(type=OrderDetailSqlProvider.class, method="insertSelective")
    int insertSelective(OrderDetail record);

    @Select({
        "select",
        "detail_id, order_id, product_id, product_name, product_price, product_quantity, ",
        "product_icon, create_time, update_time",
        "from order_detail",
        "where detail_id = #{detailId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="detail_id", property="detailId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.VARCHAR),
        @Result(column="product_id", property="productId", jdbcType=JdbcType.VARCHAR),
        @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR),
        @Result(column="product_price", property="productPrice", jdbcType=JdbcType.DECIMAL),
        @Result(column="product_quantity", property="productQuantity", jdbcType=JdbcType.INTEGER),
        @Result(column="product_icon", property="productIcon", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    OrderDetail selectByPrimaryKey(String detailId);

    @UpdateProvider(type=OrderDetailSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderDetail record);

    @Update({
        "update order_detail",
        "set order_id = #{orderId,jdbcType=VARCHAR},",
          "product_id = #{productId,jdbcType=VARCHAR},",
          "product_name = #{productName,jdbcType=VARCHAR},",
          "product_price = #{productPrice,jdbcType=DECIMAL},",
          "product_quantity = #{productQuantity,jdbcType=INTEGER},",
          "product_icon = #{productIcon,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where detail_id = #{detailId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(OrderDetail record);
}